package com.rms.recruit_management_system.controller;

import com.rms.recruit_management_system.dto.ResumeCountByDate;
import com.rms.recruit_management_system.mapper.ResumeMapper;
import com.rms.recruit_management_system.pojo.Positions;
import com.rms.recruit_management_system.service.InterviewService;
import com.rms.recruit_management_system.service.PositionsService;
import com.rms.recruit_management_system.service.ResumeService;
import com.rms.recruit_management_system.service.TalentService;
import com.rms.recruit_management_system.utils.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@Tag(name = "数据概览",description = "统计数据")
public class DashboardController {
    @Autowired
    private ResumeService resumeService;
    @Autowired
    private InterviewService interviewService;
    @Autowired
    private PositionsService positionsService;
    @Autowired
    private TalentService talentService;
    @Autowired
    private ResumeMapper resumeMapper;
    @RequestMapping("/dashboard/statistics")
    @Operation(summary = "获取统计数据",description = "统计待处理简历数量，今日面试数量，已发布职位数量，人才库数量，近一周面试人数数量和排在前五的职位投递数量")
    public Result<?> Statistic() {
        HashMap<String, Integer> statisticsMap=new HashMap<>();
        Integer pendingResumes= Math.toIntExact((Long) resumeService.getPendResumeCount());
        Integer todayInterviews= interviewService.getTodayInterviewCount();
        Integer openPositions= positionsService.getPositionsCount();
        Integer talentPoolCount= talentService.getTalentCount();
        List<Positions> positionRanking=positionsService.getPositionsSubmitCount();
        List<ResumeCountByDate> resumeTrend=resumeMapper.getResumeCountBySubmitTime();
        statisticsMap.put("pendingResumes",pendingResumes);
        statisticsMap.put("todayInterviews",todayInterviews);
        statisticsMap.put("openPositions",openPositions);
        statisticsMap.put("talentPoolCount",talentPoolCount);
        HashMap<String, Object> mapCount=new HashMap<>();
        mapCount.put("statistics",statisticsMap);
        mapCount.put("positionRanking",positionRanking);
        mapCount.put("resumeTrend",resumeTrend);
        return new Result<>(200,"success",mapCount);
    }
}
